<?php

//abstract class that defines the skeleton for all the other possible fieldbox classes to implement.
//read it well, as all fields for

abstract class smb_basefieldbox  {
    //The only header for each object you really need.
    protected $fields;
    protected $inputid; //a buildup for fields in the final HTML page.

    abstract public static function build_me( $fields, &$new_field_object );
    abstract public function show();
    abstract public function save( $post_id );

    //more functions that make certain additions on HTML code easier, depending on the flags added.
    public function add_required_label(){
        if ( isset( $this->fields['required'] ) and $this->fields['required'] ){ ?><em>**</em><?php }
        else { ?><em>&nbsp;&nbsp;</em><?php }
    }

    public function add_description(){
        if( isset( $this->fields['desc'] ) and ( !( strlen( $this->fields['desc'] ) == 0 ) ) ) {
                echo '<td>' . $this->fields['desc'] . '</td>';
        }
    }

    public static function check_page( $page ){
        global $post;
        if ( isset( $post ) and ( $post->post_type == $page ) ) { return true; }
        return false;
    }

    public function fetch_value(){
        $value = smb_basefieldbox::get($this->fields['id']);
        if ( empty($value) and isset($this->fields['default'] ) ){ $value = $this->fields['default']; }
        return $value;
    }

    static function get($name, $single = true, $post_id = null) {
        global $post;
        return get_post_meta( isset($post_id) ? $post_id : $post->ID, $name, $single);
    }

    static function set($name, $new, $post_id = null) {
        global $post;
        return update_post_meta( isset($post_id) ? $post_id : $post->ID, $name, $new);
    }

    static function delete($name, $post_id = null) {
        global $post;
        return delete_post_meta( isset($post_id) ? $post_id : $post->ID, $name);
    }

    public function get_fields(){ return $this->fields; }
    public function set_fields($fields){ $this->fields = $fields; }

    public function get_inputid(){ return $this->inputid; }
    public function set_inputid($inputid){ $this->inputid = $inputid; }
}
?>
